
function drawCanvas(){
	var ids = ["HomeLogo","exportReference", "addReference"];
	for(i in ids)
		drawCanvas_(ids[i]);
}

function drawCanvas_(id){
	var canvas = document.getElementById(id);
    if (canvas != null && id.indexOf("HomeLogo") != -1){
        var context = canvas.getContext("2d");
  		var context2 = canvas.getContext("2d");
  		var context3 = canvas.getContext("2d");
  		var context4 = canvas.getContext("2d");
  		var context5 = canvas.getContext("2d");
  		var context6 = canvas.getContext("2d");
  		var context7 = canvas.getContext("2d");

  		var radius = 15;
        var counterClockwise = false;

  		var x = 25;
        var y = 25;

  		//9-12 Uhr
        context.beginPath();
        context.arc(x, y, radius, 1.025 * Math.PI, 1.475 * Math.PI, counterClockwise);
        context.lineWidth = 2;
        // line color
        context.strokeStyle = "#4020e5";
        context.stroke();

  		//12-3 Uhr
  		context2.beginPath();
  		context2.arc(x,y,radius, 1.525 * Math.PI, 1.975 * Math.PI, counterClockwise);
  		context2.lineWidth = 2;
  		context2.strokeStyle = "#e52420 ";
  		context2.stroke();

  		//3-6 Uhr
  		context3.beginPath();
  		context3.arc(x,y,radius, 0.025 * Math.PI, 0.475 * Math.PI, counterClockwise);
  		context3.lineWidth = 2;
  		context3.strokeStyle = "#ed7d2b";
  		context3.stroke();

  		//6-9 Uhr
  		context4.beginPath();
  		context4.arc(x,y,radius, 0.525 * Math.PI, 0.975 * Math.PI, counterClockwise);
  		context4.lineWidth = 2;
  		context4.strokeStyle = "#159c2f";
  		context4.stroke();

  		context5.beginPath();
  		context5.arc(25,21, 5.25, 1 * Math.PI, 2* Math.PI, counterClockwise);
  		context5.lineWidth = 1;
  		context5.strokeStyle = "#444444";
  		context5.stroke();

  		context5.beginPath();
  		context5.arc(25,21, 2, 1 * Math.PI, 2* Math.PI, counterClockwise);
  		context5.lineWidth = 1;
  		context5.strokeStyle = "#444444";
  		context5.stroke();

  		context5.beginPath();
  		context5.arc(26.5,32, 3.4, 0 * Math.PI, 1* Math.PI, counterClockwise);
  		context5.lineWidth = 1;
  		context5.strokeStyle = "#444444";
  		context5.stroke();

  		context5.beginPath();
        context5.moveTo(27, 20.5);
        context5.lineTo(27, 30.5);
        context5.stroke();

  		context5.beginPath();
        context5.moveTo(30, 32);
        context5.lineTo(30, 21);
        context5.stroke();

  		context5.beginPath();
        context5.moveTo(23, 19.5);
        context5.lineTo(23, 32.5);
        context5.stroke();
        
  		context5.beginPath();
        context5.moveTo(20, 20.5);
        context5.lineTo(20, 30.5);
        context5.stroke();

  		context6.font = "15pt Arial";
  		context6.strokeStyle = "#444444";
  		context6.lineWidth = 1;
  		context6.strokeText("X", 45, 30);

  		context7.font = "15pt Arial";
  		context7.fillStyle = "#444444";
  		context7.fillText ("Cerpt", 57,30);
    }
    else if (canvas != null) {
    	var context = canvas.getContext("2d");
		var context2 = canvas.getContext("2d");
		var context3 = canvas.getContext("2d");
		var context4 = canvas.getContext("2d");
		var context5 = canvas.getContext("2d");
		var context6 = canvas.getContext("2d");
		
		var radius = 15;
		var counterClockwise = false;
		var x = canvas.width / 2;
		var y = canvas.height / 2;
		
		//9-12 Uhr
	    context.beginPath();
	    context.arc(x, y, radius, 1.025 * Math.PI, 1.475 * Math.PI, counterClockwise);
	    context.lineWidth = 2;
	    // line color
	    context.strokeStyle = "#4020e5";
	    context.stroke();

		//12-3 Uhr
		context2.beginPath();
		context2.arc(x,y,radius, 1.525 * Math.PI, 1.975 * Math.PI, counterClockwise);
		context2.lineWidth = 2;
		context2.strokeStyle = "#e52420 ";
		context2.stroke();

		//3-6 Uhr
		context3.beginPath();
		context3.arc(x,y,radius, 0.025 * Math.PI, 0.475 * Math.PI, counterClockwise);
		context3.lineWidth = 2;
		context3.strokeStyle = "#ed7d2b";
		context3.stroke();
		
		//6-9 Uhr
		context4.beginPath();
		context4.arc(x,y,radius, 0.525 * Math.PI, 0.975 * Math.PI, counterClockwise);
		context4.lineWidth = 2;
		context4.strokeStyle = "#159c2f";
		context4.stroke();
		
		context5.beginPath();
		context5.moveTo(20,25);
		context5.lineTo(30,25);
		context5.strokeStyle = "#444444";
		context5.stroke();

		context6.beginPath();
		context6.moveTo(25,20);
		context6.lineTo(25,30);
		context6.strokeStyle = "#444444";
		context6.stroke();
  	}
}

function showPopUp(){
	document.getElementById("darken").style.display = "block";
	document.getElementById("darken").style.width = document.body.clientWidth+"px";
	document.getElementById("darken").style.height = document.body.clientHeight+"px";
	document.getElementById("darken").style.background = "rgba(0, 0, 0, .6)";
	document.getElementById("popup").style.display = "block";
	document.getElementById("popup").style.left = (document.body.clientWidth-800)/2+"px";
	document.getElementById("popup").style.opacity = "1.0";
	

};
function closePopUp(){
	document.getElementById("darken").style.display = "none";
	document.getElementById("popup").style.display = "none";
	document.getElementById("popup").style.opacity = "0.0";
	document.getElementById("darken").style.background = "rgba(0, 0, 0, .0)";

};
function showPopUp2(i){
	
	document.getElementById("darken").style.display = "block";
	document.getElementById("darken").style.width = document.body.clientWidth+"px";
	document.getElementById("darken").style.height = document.body.clientHeight+"px";
	document.getElementById("darken").style.background = "rgba(0, 0, 0, .6)";
	document.getElementById("popup2").style.display = "block";
	document.getElementById("popup2").style.left = (document.body.clientWidth-800)/2+"px";

	document.getElementById("popup2").style.opacity = "1.0";
	xmlhttpPost_('/collaboration/reference/edit.jsp', '','popup2', '<img src=\'/img/wait.gif\'>',true, 'rid='+i+'&formprefix=edit');
	setTimeout(function(){
		changeAttributes('edit', false);
	}, 300);
};
function searchItem(){
	var q = document.getElementById("Search").value;
	var querystring = "sorting=" + sorting + "&show_references=" + showingtab + "&q=" + q;
	xmlhttpPost_('/collaboration/searchreferences.jsp', '','resultreferences', '<div class=\'waitIcon\'><img src=\'/img/wait.gif\'></div>',true, querystring);
};
function closePopUp2(){
	document.getElementById("darken").style.display = "none";
	document.getElementById("popup2").style.display = "none";
	document.getElementById("popup2").style.opacity = "0.0";
	document.getElementById("darken").style.background = "rgba(0, 0, 0, .0)";

};
function showMore(description){
	document.getElementById("infoDescription").innerHTML = description + " <strong onclick=\"showLess('" + description +"')\">less</strong>";
};
function showLess(description){
	var shortdesc = description;
	if (description.length > 150)
		 shortdesc = description.substring(0,150);
	document.getElementById("infoDescription").innerHTML = shortdesc + "... <strong onclick=\"showMore('"+description+"')\">more</strong>";
};
function showDetails(i, j){
	if(document.getElementById(i).style.display == "none"){
		document.getElementById(i).style.display = "block";
		document.getElementById("b"+i).innerHTML =  "Hide Details &#x25B2;";
		document.getElementById("c"+i).style.backgroundColor =  "#ebebeb";
		document.getElementById(i).style.height = document.getElementById(i).clientHeight+"px";
		document.getElementById(i).style.height =  j*17+"px";
		document.getElementById(i).style.opacity = "1.0"

		
	}
	else{
		
		document.getElementById("b"+i).innerHTML =  "Show Details &#x25BC;";
		document.getElementById("c"+i).style.backgroundColor =  "transparent";
		document.getElementById(i).style.height = "0px";
		document.getElementById(i).style.opacity = "0.0";		
		setTimeout(function(){setDisplayNone(i)}, 300);

	}
};
function setDisplayNone(i){
	document.getElementById(i).style.display = "none";
};

function ajaxrate(rid, rating)
{
	var query = "rid="+rid+"&rating="+rating;
	xmlhttpPost_('/collaboration/reference/rate.jsp', '',"ratingr"+rid, '<img src=\'/img/wait.gif\'>',true, query);
}

function orderby(type, querystring){
	returnreferences(type, querystring, true);
};

function returnreferences(type, querystring, alternatesorting){
	var query = generate_sorting_querystring(querystring, type, alternatesorting);
	xmlhttpPost_('/collaboration/searchreferences.jsp', '','resultreferences', '<div class=\'waitIcon\'><img src=\'/img/wait.gif\' /></div>',true, query+'&q='+document.getElementById("Search").value);
	var types = ["type", "title", "author", "relevance"];
	for (var i in types){
		var e = document.getElementById("referencetable"+types[i]+"arrow");
		if (types[i] != type)
			e.innerHTML = "";
		else{
			if (alternatesorting == true){
				if (e.innerHTML == '\u25BC')
					e.innerHTML = '\u25B2';
				else
					e.innerHTML = '\u25BC';
			}
		}
	}
	var librarytab = document.getElementById("libraryTab");
	var suggestionstab = document.getElementById("suggestionsTab");
	if (showingtab.indexOf("library") != -1){
		librarytab.className="current";
		suggestionstab.className="";
	}
	else{
		librarytab.className="";
		suggestionstab.className="current";
	}
};

var sorting = "";
var showingtab = "";

function generate_sorting_querystring(querystring, type, alternatesorting)
{
	var query, newsorting;
	
	if (querystring !==  undefined && querystring.indexOf("suggestions") != -1)
		showingtab = "show_references=suggestions";
	else{
		showingtab = "show_references=library";
	}
	
	if (querystring !== undefined)
		query = querystring + "&";
	query += "sorting=";
	if (alternatesorting == true && sorting !== undefined && sorting != "" && sorting.indexOf(type)!= -1){
		if (sorting.indexOf("ASC") != -1)
			sorting = type + "DESC";
		else if (sorting.indexOf("DESC") != -1)
			sorting = type + "ASC";
	}
	else
		sorting = type + "ASC";
	
	return query+sorting;
}

function rateover(parentid, starnumber)
{
	var starfilled = document.createTextNode("&#9733;");
	var starempty = document.createTextNode("&#9734;");
	var parent = document.getElementById(parentid);
	for(var i = 0; i < 5; i++){
		var starspan = parent.children[i];
		if (starspan.className.substring(4)*1 <= starnumber*1)
			starspan.innerHTML = "&#9733;";
		else
			starspan.innerHTML = "&#9734;";
	}
};

function rateout(parentid, rate, starnumber)
{
	var starfilled = document.createTextNode("&#9733;");
	var starempty = document.createTextNode("&#9734;");
	var parent = document.getElementById(parentid);
	for(var i = 0; i < 5; i++){
		var starspan = parent.children[i];
		if (starspan.className.substring(4)*1 < (rate*1+0.5))
			starspan.innerHTML = "&#9733;";
		else
			starspan.innerHTML = "&#9734;";
	}
};

function hideReference(id){
	document.getElementById(id).style.opacity = "0.0";
	document.getElementById(id).style.overflow = "hidden";
	document.getElementById(id).style.height = document.getElementById(id).clientHeight+"px";
	document.getElementById(id).style.height = "0px";
	setTimeout(function(){setDisplayNone(id)}, 300);
};

